package product;

public class Product {

    private String id;
    private String name;
    private int inventory;

    public Product(String id, String name, int inventory) {
        this.id = id;
        this.name = name;
        this.inventory = inventory;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getInventory() {
        return inventory;
    }

    public void setInventory(int inventory) {
        this.inventory = inventory;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", inventory=" + inventory +
                '}';
    }

    public void reduceInventory(int quantity)throws Exception{
        if (quantity > inventory) {
            throw new Exception("库存不足,无法完成订单");
        }
        inventory -= quantity;
    }

    public void increaseInventory(int quantity){
        inventory += quantity;
    }
}
